<template>
  <van-popup v-model="showDialog">
    <div class="recharge-dialog-wrap">
      <div class="dialog-title">{{ title }}</div>
      <div class="dialog-content">
        <div class="content">
          <div>充值商品：{{ money }}</div>
          <div class="account-text">充值号码：{{ account }}</div>
        </div>
        <p class="tip">请确认充值号码无误后进行充值</p>
      </div>
      <div class="footer">
        <div class="btn left" @click="handleClose">{{ cancelText }}</div>
        <div class="btn right" @click="handleSure">
          <span>{{ okText }}</span>
        </div>
      </div>
    </div>
  </van-popup>
</template>

<script>
export default {
  name: 'rechargePopup',
  props: {
    title: {
      type: String,
      default: '确认充值信息'
    },
    cancelText: {
      type: String,
      default: '取消'
    },
    okText: {
      type: String,
      default: '立即充值'
    },
    money: {
      type: [String, Number],
      default: '10'
    },
    account: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      showDialog: false,
      isLoading: false
    };
  },
  methods: {
    // 空格分隔手机号
    formatMobile() {
      return '13711111111'.replace(/^(.{3})(.*)(.{4})$/, '$1 $2 $3');
    },
    handleClose() {
      this.showDialog = false;
      this.$emit('onCancel');
    },
    handleSure() {
      // this.showDialog = false;
      if (this.isLoading) return;
      this.$emit('onOk');
    }
  }
};
</script>
<style lang="scss">
.recharge-dialog-wrap {
  .van-loading {
    height: 20px;
    width: 20px;
  }
}
</style>

<style lang="scss" scoped>
.recharge-dialog-wrap {
  width: 275px;
  background-color: #fff;
  border-radius: 4px;

  .dialog-title {
    font-size: 16px;
    font-family: PingFangSC-Medium;
    font-weight: 500;
    color: #333;
    line-height: 22px;
    text-align: center;
    padding: 20px 0 12px;
  }

  .dialog-content {
    margin-bottom: 20px;
    .content {
      width: 239px;
      margin: 0 auto;
      padding: 6px 8px;
      box-sizing: border-box;
      background: #f5f5f5;
      font-size: 14px;
      font-family: PingFangSC-Regular;
      color: #333;
      text-align: center;
      line-height: 20px;
    }
    .account-text {
      /*border: 1px solid red;*/
      word-wrap: break-word;
    }

    .tip {
      font-size: 12px;
      font-family: PingFangSC-Regular;
      font-weight: 400;
      color: #999;
      line-height: 17px;
      margin-top: 6px;
      text-align: center;
    }
  }

  .footer {
    height: 45px;
    display: flex;
    border-top: 1px solid #eee;
    .btn {
      flex: 1;
      display: flex;
      justify-content: center;
      align-items: center;
      font-weight: 400;
      font-size: 14px;
      border-right: 1px solid #eee;
      &:last-child {
        border-right: none;
      }
    }

    .left {
      color: #666;
    }

    .right {
      color: #d62222;
      font-weight: 500;
      font-family: PingFangSC-Medium;
    }
  }
}
.van-popup {
  background-color: transparent;
  border-radius: 0;
}
</style>
